package com.example.javabasic.mianshi;

import com.example.javabasic.mianshi.fuzhulei.CreateTreeNode;
import com.example.javabasic.mianshi.fuzhulei.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class Erchashu {
    public static void main(String[] args) {
        int sum = sum(CreateTreeNode.newTree());
        System.out.println(sum);
    }


    static List<String> list = new ArrayList<>();

    public static int sum(TreeNode node) {
        sums(node, "");
        System.out.println(list);
        int n = 0;
        for (String s : list) {
            n+=Integer.parseInt(s);
        }
        return n;
    }

    public static void sums(TreeNode node, String s) {
        if(node == null){
            return;
        }
        s += node.val;
        if (node.left == null&& node.right == null) {
            list.add(s);
            return;
        }
        sums(node.left, s);
        sums(node.right, s);


    }
}
